/**  
 * @Title: DownController.java
 * @Package com.limit.control.site
 * @author maoyun(maoyun0903@163.com)
 * @date 2014-4-11 上午11:14:34
 * @version V1.0
 */ 
package com.limit.control.site;

import java.util.Date;

import com.limit.constant.Constant;
import com.limit.model.Game;
import com.limit.model.GameDownRecord;
import com.limit.utils.PropertiesUtil;


/** 
 * <br/>
 * @author maoyun(maoyun0903@163.com)
 * @date 2014-4-11 上午11:14:34 
 * @version V1.0
 */

public class DownController extends BaseSiteController {

	/**
	 * android下载
	 */
	public void android(){
		long gid = this.getParaToLong("gid", 0L);
		Game game = Game.dao.findById(gid);
		if(null == game){
			this.render("500.html");
		}
		long apk_downs = game.getLong("apk_downs");
		if(apk_downs < 0)	apk_downs = 0;
		game.set("apk_downs", ++apk_downs).update();
		// save 下载记录
		GameDownRecord downRecord = this.getModel(GameDownRecord.class);
		downRecord.set("game_id", gid);
		downRecord.set("app_type", 1);
		downRecord.set("create_time", new Date());
		downRecord.set("ip", this.getRequest().getRemoteHost());
		downRecord.save();
		
		String path = Constant.androidFilePath + game.getStr("android_path");
		this.redirect(path);
	}
	
	/**
	 * ios 跳转
	 */
	public void ios(){
		long gid = this.getParaToLong("gid", 0L);
		Game game = Game.dao.findById(gid);
		if(null == game){
			this.render("500.html");
			return ;
		}
		long ios_downs = game.get("ios_downs");
		if(ios_downs < 0)	ios_downs = 0;
		game.set("ios_downs", ++ios_downs).update();
		// save 下载记录
		GameDownRecord downRecord = this.getModel(GameDownRecord.class);
		downRecord.set("game_id", gid);
		downRecord.set("app_type", 2);
		downRecord.set("create_time", new Date());
		downRecord.set("ip", this.getRequest().getRemoteHost());
		downRecord.save();
		
		String path = game.getStr("ios_path");
		this.redirect(path);
	}
	
	/**
	 * ios越狱 跳转
	 */
	public void jailBreak(){
		long gid = this.getParaToLong("gid", 0L);
		Game game = Game.dao.findById(gid);
		if(null == game){
			this.render("500.html");
			return ;
		}
		long ios_downs = game.get("ios_downs");
		if(ios_downs < 0)	ios_downs = 0;
		game.set("ios_downs", ++ios_downs).update();
		// save 下载记录
		GameDownRecord downRecord = this.getModel(GameDownRecord.class);
		downRecord.set("game_id", gid);
		downRecord.set("app_type", 2);
		downRecord.set("create_time", new Date());
		downRecord.set("ip", this.getRequest().getRemoteHost());
		downRecord.save();
		
		String path = Constant.iosIpaFilePath + game.getStr("ipa_path");
		this.redirect(path);
	}
	
	
}
